package com.yzh.design.demo.impl;

import com.yzh.design.demo.ICouponDiscount;

import java.math.BigDecimal;
import java.util.Map;

/**
 * 满减
 */
public class MJCouponDiscount implements ICouponDiscount<Map<String, String>> {
    @Override
    public BigDecimal discountAmount(Map<String, String> couponInfo, BigDecimal skuPrice) {
        String mj = couponInfo.get("MJ_MONEY");     //满减额度
        String sub = couponInfo.get("SUBTRACT_MONEY");  //减多少元
        
        //消费金额不满足满减额度
        if (skuPrice.compareTo(new BigDecimal(mj)) < 0) return skuPrice;
        
        //减去优惠金额
        BigDecimal val = skuPrice.subtract(new BigDecimal(sub));
        if (val.compareTo(BigDecimal.ZERO) < 1) return BigDecimal.ZERO;
        
        return val;
    }
}
